import axios from "axios";
const defaultConfig = {
  timeout: 5000,
  baseUrl: "",
};
const axiosInstance = axios.create(defaultConfig);
// 请求拦截
axiosInstance.interceptors.request.use(
  //  处理成功的请求
  (config) => {
    return config;
  },
  //   处理失败的请求
  (error) => {
    return Promise.reject(error);
  }
);

// 响应拦截
axiosInstance.interceptors.response.use(
  // 处理成功的响应
  (response) => {
    return response;
  },
  // 处理失败的响应
  (error) => {
    return Promise.reject(error);
  }
);

// 封装请求
// get请求
function httpRequestGet(url, params) {
  return axiosInstance
    .get(url, params)
    .then((res) => res.data)
    .catch();
}

function httpRequestPost(url, params) {
  return axiosInstance
    .post(url, params)
    .then((res) => res.data)
    .catch();
}

export default {
  httpRequestGet,
  httpRequestPost,
};
